{template 'web/_header'}
<ul class="nav nav-tabs">
    <li {if ($_GPC['p'] == 'list' || $_GPC['p'] == '') && ($_GPC['op'] == '' || $_GPC['op'] == 'display')}class="active"{/if}><a href="{php echo $this->createWebUrl('package/list')}">套盒列表</a></li>
    <li {if $_GPC['p'] == 'list' && $_GPC['op'] == 'post'}class="active"{/if}><a href="{php echo $this->createWebUrl('package/list',array('op'=>'post'))}">添加套盒二维码</a></li>
    {if $_GPC['op'] == 'qrcode'}<li class="active"><a href="javascript:;">批量生成二维码</a></li>{/if}
    <li {if $_GPC['op'] == 'download'}class="active"{/if}> <a href="{php echo $this->createWebUrl('package/list',array('op'=>'download'))}">下载二维码</a></li>
    <li {if $_GPC['op'] == 'recordall'}class="active"{/if}><a href="{php echo $this->createWebUrl('package/list',array('op'=>'recordall'))}">扫码记录</a></li>
</ul>
{if $operation == 'display'}
     <form action="" method="post">
<div class="panel panel-default">
    <div class="panel-body table-responsive">
        <table class="table table-hover">
            <thead class="navbar-inner">
                <tr>
                    <th>I_D</th>
                    <th>类型</th>
                    <th>标题</th>
                    <th>提示语</th>
                    <th>奖励余额</th>
                    <th>状态</th>
                    <th>创建时间</th>
                    <th>绑定商品ID</th>
                    <th>操作</th>
                    <th style='text-align:center;'>二维码</th>
                </tr>
            </thead>
            <tbody>
                {loop $list $row}
                <tr>
                    <td>{$row['id']}</td>
                    <td>{if $row['type'] == 1}蓝色(员工){else}红色(美容师){/if}</td>
                    <td>{$row['title']}</td>
                    <td>{$row['content']}</td>
                    <td>{if $row['type'] == 1}无{else}{$row['money']}{/if}</td>
                    <td>
                    	{if $row['status']==1}
                        <span class='label label-success'>显示</span>
                        {else}
                        <span class='label label-danger'>隐藏</span>
                        {/if}
                    </td>
                    <td>{php echo date('Y-m-d H:i:s', $row['createtime'])}</td>
                    <td>{$row['goodsid']}</td>
                    <td style="text-align:left;">
                        {ifp 'package.list.view|package.list.edit'}<a href="{php echo $this->createWebUrl('package/list', array('op' => 'post', 'id' => $row['id']))}" class="btn btn-default btn-sm" data-toggle="tooltip" data-placement="top" title="{ifp 'package.list.edit'}修改{else}查看{/if}"><i class="fa fa-edit"></i></a>{/if}
                        {ifp 'package.list.delete'}
                        <a href="{php echo $this->createWebUrl('package/list', array('op' => 'delete', 'id' => $row['id']))}" 
                        	class="btn btn-default btn-sm" onclick="return confirm('确认删除此套盒二维码?')" title="删除"><i class="fa fa-times"></i>
                       	</a>
                       	{/if}
                       	<a href="{php echo $this->createWebUrl('package/list', array('op' => 'record', 'id' => $row['id']))}" class="btn btn-default btn-sm">
                       	扫码记录</a>
                    </td>
                    <td style="text-align:center;">
                    <a href="{php echo $this->createWebUrl('package/list',array('op'=>'qrcode', 'id' => $row['id']))}" class="btn btn-default btn-sm">批量生成</a></td>
                </tr>
                {/loop}
                <tr>
                    <td colspan='10'>
                    {ifp 'package.list.add'}
                    	<a class='btn btn-default' href="{php echo $this->createWebUrl('package/list',array('op'=>'post'))}"><i class='fa fa-plus'></i> 添加套盒二维码</a>
                    {/if}
                    </td>
                </tr>
            </tbody>
        </table>
        {$pager}
    </div>
</div>
</form>
<script>
    require(['bootstrap'], function ($) {
        $('.btn').hover(function () {
            $(this).tooltip('show');
        }, function () {
            $(this).tooltip('hide');
        });
    });
    
</script>

{elseif $operation == 'post'}

<div class="main">
    <form     {ife 'package.list' $package}action="" method="post"{/if} class="form-horizontal form" enctype="multipart/form-data" onsubmit='return formcheck()'>
        <input type="hidden" name="id" value="{$id}" />
        <div class="panel panel-default">
            <div class="panel-heading">
                套盒二维码设置
            </div>
            <div class="panel-body">
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style="color:red">*</span>标题</label>
                    <div class="col-sm-9 col-xs-12">
                            {ife 'package.list' $package}
                        <input type="text" id='title' name="title" class="form-control" value="{$package['title']}" />
                           {else}
                        <div class='form-control-static'>{$package['title']}</div>
                        {/if}
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style="color:red">*</span>提示语</label>
                    <div class="col-sm-9 col-xs-12">
                            {ife 'package.list' $package}
                        <input type="text" id='content' name="content" class="form-control" value="{$package['content']}" />
                           {else}
                        <div class='form-control-static'>{$package['content']}</div>
                        {/if}
                    </div>
                </div>
                <div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">类型</label>
					<div class="col-sm-9 col-xs-12">
						<label for="radio_1" class="radio-inline"><input type="radio" name="type" id="radio_1" onclick="$('#model1').hide();" value="1" {if empty($package['type']) || $package['type'] == 1}checked="checked"{/if} /> 蓝色(员工)</label>
						<label for="radio_0" class="radio-inline"><input type="radio" name="type" id="radio_0" onclick="$('#model1').show();" value="2" {if $package['type'] == 2}checked="checked"{/if} /> 红色(美容师)</label>
						<span class="help-block"></span>
					</div>
				</div>
                <div class="form-group" id="model1" {if $package['type'] != 2} style="display:none;"{/if}>
	                <div class="form-group">
	                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style="color:red">*</span>奖励余额</label>
	                    <div class="col-sm-9 col-xs-12">
	                            {ife 'package.list' $package}
	                        <input type="text" id='money' name="money" class="form-control" value="{$package['money']}" />
	                           {else}
	                        <div class='form-control-static'>{$package['money']}</div>
	                        {/if}
	                    </div>
	                </div>
	            </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">跳转链接</label>
                    <div class="col-sm-9 col-xs-12">
                            {ife 'package.list' $package}
                        <input type="text" id='link' name="link" class="form-control" value="{$package['link']}" />
                           {else}
                        <div class='form-control-static'>{$package['link']}</div>
                        {/if}
                        <span class="help-block">默认跳转到首页</span>
                    </div>
                </div>
                
                <div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label"><span class="text-danger">*</span> 可使用的会员组</label>
					<div class="col-sm-9 col-xs-12">
						<select class="form-control" multiple="multiple" name="group[]">
							{if $group}
							{loop $group $li}
							<option value="{$li['id']}" {if $li['groupid_select'] == '1'}selected{/if}>{$li['groupname']}</option>
							{/loop}
							{/if}
						</select>
						<span class="help-block">不选择任一会员组，表示支持全部用户领取。</span>
					</div>
				</div>
				
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span>  选择商品</label>
                    <div class="col-sm-5">
                        <input type='hidden' id='goodsid' name='goodsid' value="{$package['goodsid']}" />
                        <div class='input-group'>
                            <input type="text" name="goods" value="{$package['goods']}" id="goods" class="form-control" readonly />
                            <div class='input-group-btn'>
                                <button class="btn btn-default" type="button" onclick="popwin = $('#modal-module-menus-goods').modal();">选择商品</button>
                            </div>
                        </div>
                         <span id="goodsthumb" class='help-block' {if empty($goods)}style="display:none"{/if}><img  style="width:100px;height:100px;border:1px solid #ccc;padding:1px" src="{php echo tomedia($goods['thumb'])}"/></span>
                          
                        <div id="modal-module-menus-goods"  class="modal fade" tabindex="-1">
                            <div class="modal-dialog" style='width: 920px;'>
                                <div class="modal-content">
                                    <div class="modal-header"><button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button><h3>选择商品</h3></div>
                                    <div class="modal-body" >
                                        <div class="row"> 
                                            <div class="input-group"> 
                                                <input type="text" class="form-control" name="keyword" value="" id="search-kwd-goods" placeholder="请输入商品名称" />
                                                <span class='input-group-btn'><button type="button" class="btn btn-default" onclick="search_goods();">搜索</button></span>
                                            </div>
                                        </div>
                                        <div id="module-menus-goods" style="padding-top:5px;"></div>
                                    </div>
                                    <div class="modal-footer"><a href="#" class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</a></div>
                                </div>

                            </div>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">是否显示</label>
                    <div class="col-sm-9 col-xs-12">
                            {ife 'package.list' $package}
                        <label class='radio-inline'>
                            <input type='radio' name='status' value='1' {if $package['status']==1}checked{/if} /> 是
                        </label>
                        <label class='radio-inline'>
                            <input type='radio' name='status' value='0' {if $package['status']==0}checked{/if} /> 否
                        </label>
                            {else}
                             <div class='form-control-static'>{if empty($package['status'])}否{else}是{/if}</div>
                            {/if}
                    </div>
                </div>
                 <div class="form-group"></div>
            <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
                    <div class="col-sm-9 col-xs-12">
                        {ife 'package.list' $package}
                            <input type="submit" name="submit" value="提交" class="btn btn-primary col-lg-1"  />
                            <input type="hidden" name="token" value="{$_W['token']}" />
                        {/if}
                       <input type="button" name="back" onclick='history.back()' {ifp 'package.list.add|package.list.edit'}style='margin-left:10px;'{/if} value="返回列表" class="btn btn-default" />
                    </div>
            </div>
                
                
            </div>
        </div>
      
    </form>
</div>

<script language='javascript'>
    function formcheck() {
        if ($("#title").isEmpty()) {
            Tip.focus("title", "请填写标题!");
            return false;
        }
        if ($("#content").isEmpty()) {
            Tip.focus("content", "请填写提示语!");
            return false;
        }
        if($('input[name=type]:checked').val()==2){
        	if ($("#money").isEmpty()) {
                Tip.focus("money", "请填写奖励余额!");
                return false;
            }
        	if (!$("#money").isNumber()) {
                Tip.focus("money", "请填写数字!");
                return false;
            }
        }
        if($(':input[name=goods]').val()==''){
            Tip.focus($(':input[name=goods]'),'请选择要绑定的商品!');
            return false;
        }
        return true;
    }
    
    function search_goods() {
        if( $.trim($('#search-kwd-goods').val())==''){
            Tip.focus('#search-kwd-goods','请输入关键词');
            return;
        }
		$("#module-menus-goods").html("正在搜索....")
		$.get('{php echo $this->createWebUrl('package/query')}', {
			keyword: $.trim($('#search-kwd-goods').val())
		}, function(dat){
			$('#module-menus-goods').html(dat);
		});
	}
    
	function select_good(o) {
		$("#goodsid").val(o.id);
		$("#goodsthumb").show();
		$("#goodsthumb").find('img').attr('src', o.thumb);
		$("#goods").val( "[" + o.id + "]" + o.title);
		$("#modal-module-menus-goods .close").click();
	}
	
</script>
{elseif $operation == 'record' or $operation=='recordall'}
<!-- <form action="" method="post"> -->
<form action="./index.php" method="get" class="form-horizontal" role="form" id="form1">
            <input type="hidden" name="c" value="site" />
            <input type="hidden" name="a" value="entry" />
            <input type="hidden" name="m" value="ewei_shop" />
            <input type="hidden" name="do" value="package" />
            <input type="hidden" name="p" value="list" />
            <input type="hidden" name="op" value="{$_GPC['op']}" />
            <input type="hidden" name="id" value="{$_GPC['id']}"/>
<div class="panel panel-default">
	<div class="panel-body">
	
		            <div class="form-group">
                <div class="col-sm-8 col-lg-9 col-xs-12">
                    <div class='input-group'>                      
                        <div class='input-group-addon'>用户信息</div>
                        <input class="form-control" name="member" type="text" value="<?php  echo $_GPC['member'];?>" placeholder="用户手机号/姓名/微信号/领取人 ">                        
                    </div>
                </div>
            </div> 
            <div class="form-group">

               <div class="col-sm-6">

                    <div class='input-group'>

                        <div class='input-group-addon'>下单时间
                            <label class='radio-inline' style='margin-top:-7px;'>
                                <input type='radio' value='0' name='searchtime' {if $_GPC['searchtime']=='0'}checked{/if}>不搜索
                            </label>
                            <label class='radio-inline'  style='margin-top:-7px;'>
                                <input type='radio' value='1' name='searchtime' {if $_GPC['searchtime']=='1'}checked{/if}>搜索
                            </label>
                        </div>
                        {php echo tpl_form_field_daterange('time', array('starttime'=>date('Y-m-d H:i', $starttime),'endtime'=>date('Y-m-d H:i', $endtime)),true);}
                    </div>
                </div>
            </div>
            
            <div class="form-group">

                <div class="col-sm-7 col-lg-9 col-xs-12">
                    <button class="btn btn-default"><i class="fa fa-search"></i> 搜索</button>
                    <input type="hidden" name="token" value="{$_W['token']}" />
                </div>
            </div>
	
		<div class="form-group">
			<div class="col-sm-7 col-lg-9 col-xs-12">
				<button type="submit" name="export" value="1" class="btn btn-primary">导出 Excel</button>
			</div>
		</div>
	</div>
</div>
<div class="panel panel-default">
    <div class="panel-body table-responsive">
        <table class="table table-hover">
            <thead class="navbar-inner">
                <tr>
                    <th>ID</th>
                    <th>领取类型</th>
                    <th>奖励余额</th>
                    <th>关联商品</th>
                    <th>领取时间</th>
                    <th>领取人</th>
                    <th>会员信息</th>
                    <th>微信号</th>
                    <th>会员等级</th>
                    <th>会员分组</th>
                </tr>
            </thead>
            <tbody>
                {loop $record $row}
                <tr>
                    <td>{$row['id']}</td>
                    <td>{if $row['type'] == 1}蓝色(员工){else}红色(美容师){/if}</td>
                    <td>{if $row['type'] == 2}{$row['money']}{else}无{/if}</td>
                    <td>{$row['goods']}</td>
                    <td>{$row['cdate']}<br/>{$row['ctime']}</td>
                    <td><img src="{$row['avatar']}" style="width:35px">{$row['nickname']}</td>
                    <td>{$row['realname']}<br/>{$row['mobile']}</td>
                    <td>{$row['weixin']}</td>
                    <td>{if empty($row['levelname'])}普通会员{else}{$row['levelname']}{/if}</td>
                    <td>{if empty($row['groupname'])}无分组{else}{$row['groupname']}{/if}</td>
                </tr>
                {/loop}
            </tbody>
        </table>
        {$pager}
    </div>
</div>
</form>
<script>
    require(['bootstrap'], function ($) {
        $('.btn').hover(function () {
            $(this).tooltip('show');
        }, function () {
            $(this).tooltip('hide');
        });
    });
</script>
{elseif $operation == 'qrcode'}
<div class="main">
    <form     {ife 'package.list' $package}action="" method="post"{/if} class="form-horizontal form" enctype="multipart/form-data" onsubmit='return formcheck()'>
        <div class="panel panel-default">
            <div class="panel-heading">
               批量二维码设置
            </div>
            <div class="panel-body">
            	<div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">批量生成二维码ID</label>
                    <div class="col-sm-9 col-xs-12">
                    <div class="form-control" style="border:0">{$_GPC['id']}</div>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style="color:red">*</span>回复规则名称</label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" id='name' name="name" class="form-control" value="" />
                        <span class="help-block">系统会自动生成一组名称+ID，以区分每一个规则和二维码</span>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style="color:red">*</span>触发关键字</label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" id='keyword' name="keyword" class="form-control" value="" />
                        <span class="help-block">系统会自动生成一组关键字+ID，以区分每一个推送消息</span>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style="color:red">*</span>图文消息标题</label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" id='title' name="title" class="form-control" value="" />
                    </div>
                </div>
                <div class="form-group">
				    <label class="col-xs-12 col-sm-3 col-md-2 control-label">封面</label>
				    <div class="col-sm-9 col-xs-12">
				        {php echo tpl_form_field_image('thumb', '')}
				        <span class="help-block">封面，建议尺寸: 360像素 * 200像素 </span>
				    </div>
				</div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">描述</label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" id='description' name="description" class="form-control" value="" />
                        <span class="help-block">添加图文消息的简短描述</span>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style="color:red">*</span>需要生成二维码数量</label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" id='number' name="number" class="form-control" value="" />
                        <span class="help-block">为防止系统长时间无响应，生成二维码数量请少于500张</span>
                    </div>
                </div>
                <!-- 
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">二维码颜色</label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" id='color' name="color" class="form-control" value="" />
                        <span class="help-block">此处可以不填写，如不填写，则默认天使红色 FF0000，员工蓝色 0000FF</span>
                    </div>
                </div> -->
                <div class="form-group" id="model1">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">过期时间</label>
					<div class="col-sm-9 col-xs-12">
						{php echo tpl_form_field_date('endtime', date('Y-m-d H:i', time()+604800), true)}
			            <div class="help-block">输入二维码失效截止时间</div>
					</div>
				</div>
                <!-- 
                <div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">二维码类型</label>
					<div class="col-sm-9 col-xs-12">
						<label for="radio_1" class="radio-inline"><input type="radio" name="qrc-model" id="radio_1" onclick="$('#model2').hide();$('#model1').show();" value="1" checked="checked"/> 临时</label>
						<label for="radio_0" class="radio-inline"><input type="radio" name="qrc-model" id="radio_0" onclick="$('#model1').hide();$('#model2').show();" value="2"  /> 永久</label>
						<span class="help-block">目前有2种类型的二维码, 分别是临时二维码和永久二维码, 前者有过期时间, 但能够生成较多数量, 后者无过期时间, 数量较少(目前参数只支持1--100000).</span>
					</div>
				</div>
				<div class="form-group" id="model1">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">过期时间</label>
					<div class="col-sm-9 col-xs-12">
						{php echo tpl_form_field_daterange('time', array('start'=>date('Y-m-d H:i:s',time()),'end'=>date('Y-m-d H:i:s',time()+604800)), true)}
			            <div class="help-block">输入二维码起止时间</div>
					</div>
				</div>
				<div class="form-group" id="model2" style="display:none;">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">场景值</label>
					<div class="col-sm-9 col-xs-12">
						<input type="text" class="form-control" placeholder="场景值" id="scene_str" name="scene_str" value="{$row['scene_str']}" />
						<span class="help-block">场景值不能重复，只能是字符串或汉字，不能是数字，仅永久二维码支持。<strong class="text-danger">此处可为空</strong></span>
					</div>
				</div>
				 -->
                <div class="form-group"></div>
            	<div class="form-group">
                	<label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
                	<div class="col-sm-9 col-xs-12">
                       	<input type="submit" name="submit" value="提交" class="btn btn-primary col-lg-1"  />
                        <input type="hidden" name="token" value="{$_W['token']}" />
                   		<input type="button" name="back" onclick='history.back()' style='margin-left:10px;' value="返回列表" class="btn btn-default" />
                	</div>
            	</div>
            </div>
        </div>
    </form>
</div>
<script language='javascript'>
    function formcheck() {
        if ($("#name").isEmpty()) {
            Tip.focus("name", "请填写回复规则名称!");
            return false;
        }
        if ($("#keyword").isEmpty()) {
            Tip.focus("keyword", "请填写触发关键字!");
            return false;
        }
        if ($("#title").isEmpty()) {
            Tip.focus("title", "请填写图文消息标题!");
            return false;
        }
        if ($("#number").isEmpty()) {
            Tip.focus("number", "请填写需要生成二维码的数量!");
            return false;
        }
        if ($("#number").val()>500) {
            Tip.focus("number", "为防止系统长时间无响应，生成二维码数量请少于500张!");
            return false;
        }
        return true;
    }
</script>
{elseif $operation == 'download'}
<form action="" method="post">
<div class="panel panel-default">
    <div class="panel-body table-responsive">
        <table class="table table-hover">
            <thead class="navbar-inner">
                <tr>
                    <th style="width:10%">ID</th>
                    <th style="width:30%">名称</th>
                    <th style="width:20%">创建时间</th>
                    <th style="width:20%">失效时间</th>
                    <th style='width:20%'>操作</th>
                </tr>
            </thead>
            <tbody>
                {loop $list $row}
                <tr>
                    <td style="width:10%">{$row['id']}</td>
                    <td style='width:30%'>{$row['name']}</td>
                    <td style='width:20%'>{$row['createtime']}</td>
                    <td style='width:20%'>{if $row['endtime'] != ''}{php echo date('Y-m-d H:i:s',$row['endtime'])}{/if}</td>
                    <td style="text-align:left;width:20%">
                    	<a href="{$row['downlink']}" class="btn btn-default btn-sm">
                       	下载压缩包</a>
                        <a href="{$row['deletelink']}" 
                        	class="btn btn-default btn-sm" onclick="return confirm('确认删除此压缩包?')" title="删除"><i class="fa fa-times"></i>删除压缩包
                       	</a>
                    </td>
                </tr>
                {/loop}
            </tbody>
        </table>
        {$pager}
    </div>
</div>
</form>
{/if}
{template 'web/_footer'}